package kr.hkit.powerjava.chapter14.windowbuilder;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.BoxLayout;
import javax.swing.JButton;

public class BoxLayoutEx02 extends JFrame {

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BoxLayoutEx02 frame = new BoxLayoutEx02();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BoxLayoutEx02() {
		initialize();
	}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		JPanel contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane); //setcontentpane쓰면 setvisiable, add안해도됨
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		
		makeButton(contentPane, "Button 01");
		makeButton(contentPane, "Button 02");
		makeButton(contentPane, "Button 03");
		makeButton(contentPane, "Button 04");
		makeButton(contentPane, "Button 05");
		pack();
		
		//아래 코드 줄어들었음! 
		/*JButton btnNewButton = new JButton("New button");
		contentPane.add(btnNewButton);
		JButton btnNewButton_1 = new JButton("New button");
		contentPane.add(btnNewButton_1);
		JButton btnNewButton_2 = new JButton("New button");
		contentPane.add(btnNewButton_2);
		JButton btnNewButton_3 = new JButton("New button");
		contentPane.add(btnNewButton_3);
		JButton btnNewButton_4 = new JButton("New button");
		contentPane.add(btnNewButton_4);*/
	}
	
	private void makeButton(JPanel panel, String text) {
		JButton button = new JButton(text);
		button.setAlignmentX(CENTER_ALIGNMENT);
		panel.add(button);
		
	}
}
